<?php

class Suburbians_modul  extends CI_Model {
	public $select;
	public $dollars;
 
	public function __construct() {
		// Call the Model constructor
		parent::__construct();

		$this -> fproperty();
		$this-> dollars=30;
	}




    /**
     * Поиск наглавной главная
     *
     * @return void
     * @author
     */

    public function request($get = false, $start = 0, $finish = 30) {

        $data = false;
   
        $DB2 = $this -> load -> database('adsent', TRUE, TRUE);
    $select = "SELECT   
    r.id,  
    r.area,
    r.site,
    r.object_type ,
    r.adress_name,
    r.region_names,
    r.region_id,
    r.city_name,
    r.city_id,
    r.street_name,
    r.street_id,
    r.home_id, 
    r.price,
    r.currency,  
       
    r.currency, 
    r.floorn,
    r.newtime, 
    
    r.comment_client,
    r.comment_site,
    r.keepday, 
    r.contact_telefon1,
    r.contact_name1,
    r.contact_telefon2,
    r.contact_name2,
    r.id_phone,
    r.act,
    r.datetime,
    r.moderator,
 
    r.name_metro,
    r.id_metro
   FROM `ssuburbian` `r`
   $get
   GROUP BY r.id
   LIMIT $start,$finish;";
        $q = $DB2 -> query($select);
        $data = $this->req($q); 
        return $data;
    }
 
 
 
 
  
  
   
	public function fproperty() {
		$lt = false;

		$DB2 = $this -> load -> database('adsent', TRUE, TRUE);
		$query = $DB2 -> query("SELECT * FROM `property`");

		if ($query -> num_rows() > 0) {
			foreach ($query->result() as $row) {
				$lt[$row -> text] = $row -> val; 
			}
		}
		$this->property = 	$lt;
		return;
	}

       
    
    /**
     * 
     * @param $array - массив с данными для разбора 
     * 
     * */
    public function req($datas){
         $data =  array();
		 $this -> load -> helper('text');
   	$this -> load -> helper('see');
        if ($datas -> num_rows() > 0) {

            foreach ($datas -> result() as $row) {

                $data[] = array(                
                'id'  => $row -> id,
                'root'  => sale_suburbian_object_type($row -> object_type),
                'area'  => $row -> area,
                'site'  => $row -> site,
                'r_adress_name'  => $row -> adress_name,
                'r_region_names'  => $row -> region_names,
                'r_region_id'  => $row -> region_id,
                'r_city_name'  => $row -> city_name,
                'r_city_id'  => $row -> city_id,
                'r_street_name'  => $row -> street_name,
                'r_street_id'  => $row -> street_id,
                'r_home_id'  => $row -> home_id,  
                 
                'price_dollar' => rent_flat_current($row -> price, $row -> currency,'dollars',$this->dollars),
				   'price_rubley' => rent_flat_current($row -> price, $row -> currency, 'rubley',$this->dollars),
				
                
                'd_price'  => $row -> price,
                
                
                
                  'currency'  => $row -> currency,
                
                
                'newtime'  => $row -> newtime,
                
                
                
               
                'floorn'  => $row -> floorn,
                
                 
                'comment_client'  => $row -> comment_client,
                'r_comment_site'  => $row -> comment_site,
                'r_keepday'  => $row -> keepday,
     
                'contact_telefon1'  => $row -> contact_telefon1,
                'contact_name1'  => $row -> contact_name1,
                'contact_telefon2'  => $row -> contact_telefon2,
                'contact_name2'  => $row -> contact_name2,
                'r_id_phone'  => $row -> id_phone,
                'r_act'  => $row -> act,
                'datetime'  => $row -> datetime,
                'newday'  => $row -> datetime,
                'r_moderator'  => $row -> moderator,
                
                
                'metro' => $row -> name_metro, 
                'metro_id' => $row -> id_metro, 
                'adsent' => 'ssuburbian', 
                 
                 );
            }
        } 
        return $data;
    }
    
   

}

